package com.easyCms.base.web;

import com.easyCms.base.busi.UserAuthBusi;
import com.easyCms.base.entity.AppApplyList;
import com.easyCms.base.entity.ResultBean;
import com.easyCms.base.utils.ControllerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.PrintWriter;
import java.util.List;

@Controller
@RequestMapping(value = "/userAuthData")
public class UserAuthDataController {
    private static Logger logger = LoggerFactory.getLogger(UserAuthDataController.class);
    @Autowired
    private UserAuthBusi userAuthBusi;

    /**
     * 用户审核单数据
     */
    @RequestMapping(value = "/getUserApplyList", method = RequestMethod.GET)
    public @ResponseBody
    ResultBean getUserApplyList(PrintWriter printWriter,
                                @RequestParam(value = "page", defaultValue = "1") int pageNumber,
                                @RequestParam(value = "limit", defaultValue = "10") int pageSize) {
        try {
            List<AppApplyList> datas = userAuthBusi.getUserApplyList(pageNumber, pageSize);
            return ControllerUtils.outputLayuiGrid(printWriter, datas, logger);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return null;
    }

    /**
     * 用户审核单数据
     */
    @RequestMapping(value = "/editUserApply", method = RequestMethod.POST)
    public @ResponseBody
    ResultBean editUserApply(PrintWriter printWriter,
                             @RequestParam(value = "operatorType") int operatorType, @RequestParam(value = "applyId") Long applyId,
                             String comment) {
        ResultBean result = new ResultBean();
        try {
            result = userAuthBusi.editUserApply(operatorType, applyId, comment, result);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return result;
    }
}
